import axios from 'axios';
import qs from 'qs';
import util from "@/utils/util.js";

const BASE_URL = import.meta.env.VITE_API
const api = axios.create({
  baseURL: BASE_URL,
});
export default {
  getDatasourceList(param) {
    return api.get('/datasourceManage/list', param)
  },
  analysis(param) {
    return api.post('/diff/analysis', {
      ...param
    })
  },
  addDatasource(param) {
    return api.post('/datasourceManage/add', {
      ...param
    })
  },
  updateDatasource(param) {
    return api.post('/datasourceManage/update', {
      ...param
    })
  },
  deleteDatasource(param) {
    return api.post('/datasourceManage/delete', {
      ...param
    })
  },
  testConnection(param){
    return api.post('/datasourceManage/testConnection', {
      ...param
    })
  },
  getDatasourceTypes() {
    return ['mysql', 'oracle', 'sqlserver', 'pgsql', 'tidb', 'h2']
  },
  sync(param) {
    return api.post('/datasourceManage/sync', param)
  },
  histories(param) {
    return api.get('/history/list?' + qs.stringify(param))
  },
  deleteHistory(param) {
    return api.post('/history/delete', param)
  },
  downloadReport(param) {
    util.download(BASE_URL + 'diff/report', 'post', param)
  }
}
